// import { getQiniuToken, uploadImage } from 'api/qiniu'
import { getQiniuToken } from 'api/qiniu'
const qiniu = {
  state: {
    qiniuToken: '',
    qiniuPrefix: 'http://upload.qiniu.com/', // 七牛上传网址前缀
    qiniuUpload: 'http://7xrgfl.com1.z0.glb.clouddn.com/' // 自己七牛空间网址前缀
  },
  mutations: {
    SET_QINIU_TOKEN(state, token) {
      state.qiniuToken = token.data
    }
  },
  actions: {
    // 获取qiniu 上传 token
    GetQiniuToken({ commit }) {
      return new Promise((resolve, reject) => {
        getQiniuToken().then(response => {
          commit('SET_QINIU_TOKEN', response.data)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
    // UploadImage({ commit }, info) {
    //   const token = info.token
    //   const file = info.file
    //   return new Promise((resolve, reject) => {
    //     uploadImage(file, token).then(response => {
    //       // commit('SET_QINIU_IMG', response.data)
    //       resolve(response.data)
    //     }).catch(err => {
    //       reject(err)
    //     })
    //   })
    // }
  }
}
export default qiniu
